package tsing.javase.caffenie;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import lombok.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @Author Tsing/吴清平
 * @Date 2023/1/29 18:42
 * @Version 1.0
 */
@Configuration
public class CaffeineConfig {


    @Bean
    public Cache<String,String> stringCache(){
        return Caffeine.newBuilder().
                initialCapacity(100)   //初始长度
                .maximumSize(10_000)   //最大长度
                .expireAfterWrite(5, TimeUnit.MINUTES)  // 最后一次写入后多久过期
                .build();

    }

}
